package com.tarena.lbs.user.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.user.dao.mapper.UserTagsMapper;
import com.tarena.lbs.user.dao.repository.UserTagsRepository;
import com.tarena.lbs.user.pojo.po.UserTagsPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Repository
public class UserTagsRepositoryImpl implements UserTagsRepository {
    @Autowired
    private UserTagsMapper userTagsMapper;

    @Override
    public void insert(Integer userId, List<Integer> idList) {
        List<UserTagsPO> poList = new ArrayList<>();
        for (Integer id : idList) {
            UserTagsPO po = new UserTagsPO();
            po.setUserId(userId);
            po.setTagId(id);
            poList.add(po);
        }
        userTagsMapper.insert(poList);
    }

    @Override
    public List<UserTagsPO> queryByUserId(Integer userId) {
        QueryWrapper<UserTagsPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return userTagsMapper.selectList(queryWrapper);
    }
}
